//
//  ViewModel.m
//  UICollectionViewAdvance
//
//  Created by GuochengLiu on 2016/12/23.
//  Copyright © 2016年 sumavision. All rights reserved.
//

#import "ViewModel.h"

@implementation ViewModel

- (void)fetchDataWithCompleted:(ViewModelCompletion)completed sectionCompleted:(ViewModelSectionCompletion)sectionCompleted
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        NSMutableArray *array = [NSMutableArray array];
        
        {
            LiveColumn *column = [[LiveColumn alloc] init];
            column.columnName = @"猜你喜欢";
            column.columnID = @"cainixihuan";
            [array addObject:column];
        }
        {
            LiveColumn *column = [[LiveColumn alloc] init];
            column.columnName = @"猜你讨厌";
            column.columnID = @"cnty";
            [array addObject:column];
        }
        {
            LiveColumn *column = [[LiveColumn alloc] init];
            column.columnName = @"高清频道";
            column.columnID = @"HD";
            [array addObject:column];
        }

        self.arrayColumn = array;
        completed(self, nil);
        
        
        for (LiveColumn *liveColumn in _arrayColumn) {
            
            NSInteger randomNumber = arc4random()%4 + 1;
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(randomNumber * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                liveColumn.arrayChannel = @[@"CCTV1", @"CCTV2", @"CCTV3", @"CCTV4"];
                
                sectionCompleted(self, liveColumn, [_arrayColumn indexOfObject:liveColumn]);
            });
        }
    });
}


@end
